<?php

namespace Mini;

class App
{
    protected static ?EventLoop $loop = null;
    protected static array $config = [];

    public static function loop(): EventLoop
    {
        if (!self::$loop) {
            self::$loop = new EventLoop();
        }
        return self::$loop;
    }

    public static function config(string $key = '', $default = null)
    {
        if (empty(self::$config)) {
            self::$config = require BASE_PATH . '/config/app.php';
        }

        if ($key === '') {
            return self::$config;
        }

        return self::$config[$key] ?? $default;
    }
}
